package cmd

import (
	"fmt"
	"github.com/howeyc/gopass"
	"github.com/urfave/cli/v2"
)

var (
	userName, password string
)

var AuthorityCmd = []*cli.Command{
	{
		Name:     "authority",
		Aliases:  []string{"a", "auth"},
		Usage:    "System Authorization Management",
		Category: "Authorization",
		Subcommands: []*cli.Command{
			{
				Name:    "login",
				Aliases: []string{"l", "ll"},
				Usage:   "The user login",
				Flags: []cli.Flag{
					&cli.StringFlag{
						Name:        "user",
						Aliases:     []string{"u", "uu"},
						Usage:       "user name",
						Destination: &userName,
					},
				},
				Action: func(context *cli.Context) error {
					if len(userName) > 0 {
						fmt.Print("Password: ")
						if pass, err := gopass.GetPasswd(); err != nil {
							return err
						} else {
							fmt.Println("pass: ", string(pass))
						}

					}
					return nil
				},
			},
			{
				Name:    "logout",
				Aliases: []string{"o", "oo"},
				Usage:   "The user logout",
				Action: func(context *cli.Context) error {
					return nil
				},
			},
			{
				Name:    "register",
				Aliases: []string{"r", "rr"},
				Usage:   "The user register",
				Flags: []cli.Flag{
					&cli.StringFlag{
						Name:        "user",
						Aliases:     []string{"u", "uu"},
						Usage:       "user name",
						Destination: &userName,
					},
				},
				Action: func(context *cli.Context) error {
					return nil
				},
			},
		},
	},
}
